package com.kexio.auth.dto;

import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * 角色信息DTO
 * 
 * 封装用户角色的基本信息和数据权限范围配置
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class RoleInfo implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 角色ID
     */
    private String roleId;
    
    /**
     * 角色编码
     */
    private String roleCode;
    
    /**
     * 角色名称
     */
    private String roleName;
    
    /**
     * 数据权限范围：ALL/DEPT/DEPT_AND_CHILD/SELF/CUSTOM
     */
    private String dataScope;
    
    /**
     * 自定义部门ID列表（当dataScope为CUSTOM时使用）
     */
    private List<String> customDeptIds;
    
    /**
     * 角色状态：1-启用，0-禁用
     */
    private Integer status;
    
    /**
     * 角色描述
     */
    private String description;
    
    // ==================== 构造函数 ====================
    
    public RoleInfo() {}
    
    public RoleInfo(String roleId, String roleCode, String roleName) {
        this.roleId = roleId;
        this.roleCode = roleCode;
        this.roleName = roleName;
    }
    
    public RoleInfo(String roleId, String roleCode, String roleName, String dataScope) {
        this(roleId, roleCode, roleName);
        this.dataScope = dataScope;
    }
    
    // ==================== 便捷方法 ====================
    
    /**
     * 判断是否为超级管理员角色
     */
    @JsonIgnore
    public boolean isSuperAdmin() {
        return "SUPER_ADMIN".equals(this.roleCode);
    }
    
    /**
     * 判断角色是否启用
     */
    @JsonIgnore
    public boolean isEnabled() {
        return status != null && status == 1;
    }
    
    /**
     * 判断是否有全部数据权限
     */
    @JsonIgnore
    public boolean hasAllDataScope() {
        return "ALL".equals(this.dataScope);
    }
    
    /**
     * 判断是否为自定义数据权限
     */
    @JsonIgnore
    public boolean isCustomDataScope() {
        return "CUSTOM".equals(this.dataScope);
    }
    
    // ==================== Getter/Setter ====================
    
    public String getRoleId() {
        return roleId;
    }
    
    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }
    
    public String getRoleCode() {
        return roleCode;
    }
    
    public void setRoleCode(String roleCode) {
        this.roleCode = roleCode;
    }
    
    public String getRoleName() {
        return roleName;
    }
    
    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }
    
    public String getDataScope() {
        return dataScope;
    }
    
    public void setDataScope(String dataScope) {
        this.dataScope = dataScope;
    }
    
    public List<String> getCustomDeptIds() {
        return customDeptIds;
    }
    
    public void setCustomDeptIds(List<String> customDeptIds) {
        this.customDeptIds = customDeptIds;
    }
    
    public Integer getStatus() {
        return status;
    }
    
    public void setStatus(Integer status) {
        this.status = status;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    @Override
    public String toString() {
        return "RoleInfo{" +
                "roleId='" + roleId + '\'' +
                ", roleCode='" + roleCode + '\'' +
                ", roleName='" + roleName + '\'' +
                ", dataScope='" + dataScope + '\'' +
                ", customDeptIds=" + customDeptIds +
                ", status=" + status +
                ", description='" + description + '\'' +
                '}';
    }
}
